package com.gjm.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class MyTimeRecordAspect {

    @Around("@annotation(com.gjm.demo.aspect.MyAspect)")
    public Object timeRecord(ProceedingJoinPoint pjp) throws Throwable {
        log.info("do before");

        long begin = System.currentTimeMillis();

        Object proceed = null;

        try {
            proceed = pjp.proceed();
        } catch (Throwable e){
            log.info("do afterThrowing");
            return proceed;
        }

        long end = System.currentTimeMillis();

        log.info("方法耗时: " + (end - begin) + "ms");

        log.info("do after");

        return proceed;
    }
}
